<?php

namespace app\v1\controller;

use think\Controller;
use think\Request;
use think\Validate;

/**
 * Class Device
 * @package app\v1\controller
 * 监控模块的控制器
 */
class Device extends Authorization
{
    /**
     * 获取设备监控列表
     */
    public function index()
    {
        //
    }

    //获取第三方参数测试
    public function getDeviceList(){
        $device=model('v1/Device');
        $device->getHttpDeviceList('kjufq73a');
        //dump(httpRequest($url,$header,$data));
    }

    //获取设备列表还有配置
    public function getDeviceConfig(){
        $device=model('v1/Device');
        $device->getDeviceConfig();
    }

    //获取莹石access_token
//    public function getAccessToken(){
//        $device=model('v1/Device');
//        $device->getEzAccessToken();
//    }
    //获取nvr的html地址
//    public function getHtmlUrl(){
//        $device=model('v1/Device');
//        $info=$device->getHtmlUrl('G40S177J00',1);
//    }

    //获取莹石直播监控地址
//    public function getEzVideoUrl(){
//        $device=model('v1/Device');
//        $device->getEzVideoUrl('822201681',1);
//    }

    //获取监控地址
    public function getVideoUrl(){
        $type=input('type');
        $deviceSerial=input('deviceSerial');
        $channelNo=(int)input('channelNo',0,'int');
        $validate=new Validate([
            'type'=>'require',
            'deviceSerial'=>'require',
            'channelNo'=>'require'
        ]);
        $validate->message([
            'type'=>'请出入监控类型参数',
            'deviceSerial'=>'请传入设备序列号',
            'channelNo'=>'请填写通道参数'
        ]);
        $data=$this->request->post();
        if(!$validate->check($data)){
            renderInfo(400001,$validate->getError());
        }
        $returnData=array();
        $device=model('v1/Device');
        if($type=='nvr'){
            $device->checkSchoolSerial($type,$deviceSerial);
            $info=$device->getHtmlUrl($deviceSerial,$channelNo);
            $returnData['videoUrl']=$info['html5_url'];
            $returnData['msg']=$info['msg'];
        }else if($type=='ez'){
            $device->checkSchoolSerial($type,$deviceSerial);
            $info=$device->getEzVideoUrl($deviceSerial,$channelNo);
            if($info['code']==200){
                $returnData['videoUrl']=$info['data']['liveAddress'];
                $returnData['msg']=$info['msg'];
            }else{
                $returnData['videoUrl']="";
                $returnData['msg']=$info['msg'];
            }

        }else{
            renderInfo(400001,'请填写正确的监控类型');
        }
//        dump($info);
//        die;
        renderData(0,'ok',$returnData);
    }
    //测试视频加密关闭
    public function offEncryption(){
        $device=model('v1/Device');
        $device->offEncryption('sfd','sf');
    }



}
